﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using TarreOA.TarreOABLL;
using TarreOA.TarreOAModels;

public partial class PublicCommunication_FindLinkManByBirthday : System.Web.UI.Page
{
    private string startDate;
    private string endDate;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            this.txtStartDate.Attributes.Add("onfocus", "calendar()");
            this.txtEndDate.Attributes.Add("onfocus", "calendar()");
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        startDate = Request.Form.Get(this.txtStartDate.ClientID);
        endDate = Request.Form.Get(this.txtEndDate.ClientID);
        this.DataList_DataTable();
        ViewState["startDate"] = startDate;
        ViewState["endDate"] = endDate;
    }

    protected void DataList_DataTable()
    {
        PublicCommunicationGroupLinkManService pcgLmService = new PublicCommunicationGroupLinkManService();
        List<PublicCommunicationGroupLinkMantb> list = pcgLmService.findByBirthday(startDate, endDate);
        if (list != null && list.Count > 0)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("GroupLinkManId", typeof(string));
            dt.Columns.Add("GroupLinkManName", typeof(string));
            dt.Columns.Add("GroupLinkManHandset", typeof(string));
            dt.Columns.Add("GroupLinkManSec", typeof(string));
            dt.Columns.Add("GroupLinkManUnitTelephone", typeof(string));
            dt.Columns.Add("GroupLinkManEmail", typeof(string));
            dt.Columns.Add("GroupLinkManSmallHand", typeof(string));
            foreach (PublicCommunicationGroupLinkMantb pcgLinkMan in list)
            {
                DataRow dr = dt.NewRow();
                dr["GroupLinkManId"] = pcgLinkMan.GroupLinkManId.ToString();
                dr["GroupLinkManName"] = pcgLinkMan.GroupLinkManName;
                dr["GroupLinkManHandset"] = pcgLinkMan.GroupLinkManHandset;
                dr["GroupLinkManSec"] = pcgLinkMan.GroupLinkManSec == 0 ? "男" : "女";
                dr["GroupLinkManUnitTelephone"] = pcgLinkMan.GroupLinkManUnitTelephone;
                dr["GroupLinkManEmail"] = pcgLinkMan.GroupLinkManEmail;
                dr["GroupLinkManSmallHand"] = pcgLinkMan.GroupLinkManMsn;
                dt.Rows.Add(dr);
            }
            this.DataList1.DataSource = dt.DefaultView;
            this.DataList1.DataBind();
        }
        else
        {
            this.DataList1.DataSource = null;
            this.DataList1.DataBind();
        }
    }
    protected void DataList1_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
        {
            string pcglm_id = ((HtmlInputHidden)e.Item.FindControl("HidLinkManId")).Value;
            ((HyperLink)e.Item.FindControl("HylInfo")).Attributes.Add("onclick", "return openLinkManDialogWindow(" + pcglm_id + ")");
            ((HyperLink)e.Item.FindControl("HylEdit")).NavigateUrl = "UpdateGroupLinkMan.aspx?pcglm_id=" + pcglm_id;
            ((LinkButton)e.Item.FindControl("LbtDelete")).Attributes.Add("pcglm_id", pcglm_id);
            ((LinkButton)e.Item.FindControl("LbtDelete")).Attributes.Add("onclick", "javascript:return confirm('您确认删除此联系人吗？')");
        }
    }

    protected void LbtDelete_Click(object sender, EventArgs e)
    {
        if (ViewState["startDate"] != null && ViewState["endDate"] != null)
        {
            startDate = (string)ViewState["startDate"];
            endDate = (string)ViewState["endDate"];
        }
        int pcglm_Id = int.Parse(((LinkButton)sender).Attributes["pcglm_id"]);
        PublicCommunicationGroupLinkManService pcgLmService = new PublicCommunicationGroupLinkManService();
        if (pcgLmService.delByPcglmid(pcglm_Id) == 1)
        {
            this.DataList_DataTable();
        }
        else
        {
            ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('删除失败，请重试！');", true);
        }
        ViewState["startDate"] = startDate;
        ViewState["endDate"] = endDate;
    }
}
